package westh.ilib.struts.action.manage.conference;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOMessage;

import westh.config.Config;
import westh.ilib.bean.manage.ConferenceBean;
import westh.ilib.struts.action.manage.conference.ConferenceListPreAction;
import westh.util.YyAction;
import westh.config.Config;

public class ConferenceListPreAction extends YyAction 
{
	//define commons log
	private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
			.getLog(ConferenceListPreAction.class);
	//get clouds Ip address
	String localhostUrl = Config.get("localhostUrl");
	String remoteUrl = Config.get("remoteUrl");

	public ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		// 日志和权限检查，请勿删除
		westh.log.YyLog.addFootprint(request, "动作-学术会议列表");
		/**
		 * ****************in data start********************************************
		 */
		// 查询数据文件
		String dbName = "conference.dbxml";
		JSONObject inJson = new JSONObject();
		//inJson.put("queryStr", myQuery);
		inJson.put("dbName", dbName);
		String inputStr = inJson.toString();
		/**
		 * ****************in data end********************************************
		 */
		String outString = "";
		try
		{
			MuleClient clientD = new MuleClient();
			// 调用WebService
			UMOMessage umo = clientD.send("axis:http://"+remoteUrl+":4381/LIBJson/iDlibJson?method=getConferenceList",inputStr, null);
			outString = (String) umo.getPayload();
			log.debug(" outString="+outString);
		} catch (Exception e)
		{
			throw new RuntimeException(e);
		}
		// 解析outString
		JSONObject conferenceOutStr = JSONObject.fromObject(outString);
		String retCode = conferenceOutStr.getString("retCode");
		List list = new ArrayList();
		ConferenceBean conference = new ConferenceBean();
		// 判断
		if (retCode.equals("0100")) 
		{
			String result = conferenceOutStr.getString("result");
			JSONArray resultArry = JSONArray.fromObject(result);
			int size = resultArry.size();
			for (int i = 0; i < size; i++)
			{
				conference = new ConferenceBean();
				JSONObject jsonobj = JSONObject.fromObject(resultArry.get(i));
				conference.setConferenceId(jsonobj.getString("conferenceId"));
//				conference.setCategory(outJson.getString("category"));
				conference.setConferenceName(jsonobj.getString("conferenceName"));
				conference.setConferenceFullName(jsonobj.getString("conferenceFullName"));
				conference.setConferenceDateStart(jsonobj.getString("conferenceDateStart"));
				conference.setConferenceDateEnd(jsonobj.getString("conferenceDateEnd"));
				conference.setConferenceVenue(jsonobj.getString("conferenceVenue"));
				conference.setConferenceDeadline(jsonobj.getString("conferenceDeadline"));
				conference.setConferenceNotification(jsonobj.getString("conferenceNotification"));
				conference.setConferenceCameraReady(jsonobj.getString("conferenceCameraReady"));
				conference.setConferenceDateReg(jsonobj.getString("conferenceDateReg"));
				conference.setConferenceUrl(jsonobj.getString("conferenceUrl"));
				list.add(conference);
			}
		}
		request.setAttribute("list", list);
		return mapping.findForward("succ");
	}

}
